<template>
  <div class="col-md-8">
    <h3 class="reply">评论回复：</h3>
    <ul class="list-group">
      <CommentItem
        v-for="comment in comments"
        :key="comment.id"
        :comment="comment"
      />
    </ul>
  </div>
</template>

<script>
import CommentItem from "../CommentItem";

export default {
  name: "CommentList",
  components: {
    CommentItem,
  },
  data() {
    return {
      comments: [
        { id: 1, username: "好汉1", content: "路见不平一声吼啊" },
        { id: 2, username: "好汉2", content: "该出手时就出手" },
      ],
    };
  },
  methods: {
    addComment(username, content) {
      this.comments.push({
        id: Date.now(),
        username,
        content,
      });
    },
  },
  mounted() {
    this.$bus.$on("addComment", this.addComment);
  },
  beforeDestroy() {
    this.$bus.$off("addComment", this.addComment);
  },
};
</script>

<style>
/* list */
.reply {
  margin-top: 0px;
}
</style>
